package com.diligent.cloud.sfc.resources.impl;

import com.canny.commons.model.ObjectResult;
import com.canny.commons.model.Result;
import com.diligent.cloud.sfc.model.OrderCompleteParams;
import com.diligent.cloud.sfc.model.params.inventory.AddPackingInventoryParams;
import com.diligent.cloud.sfc.resources.WorkshopScenePackingResource;
import com.diligent.cloud.sfc.service.WorkshopScenePackingService;
import com.diligent.cloud.web.resource.impl.AbstractActionResourceImpl;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * WorkshopScenePackingResourceImpl class
 *
 * @author xf107278
 * @date 4/20/2020
 */
@RestController
public class WorkshopScenePackingResourceImpl extends AbstractActionResourceImpl implements WorkshopScenePackingResource {
    private WorkshopScenePackingService workshopScenePackingService;

    public WorkshopScenePackingResourceImpl(WorkshopScenePackingService workshopScenePackingService) {
        this.workshopScenePackingService = workshopScenePackingService;
        init();
    }

    @Override
    public ResponseEntity<ObjectResult> selectById(Long id) {
        return null;
    }

    private void init(){
        super.registerAction(HttpMethod.POST.toString(), "addPackingInventory", AddPackingInventoryParams.class, (var1, var2, var3) -> {

            return workshopScenePackingService.addPackingInventory(var3.getPackingInventoryParams(),var3.getPrincipal());
        });
    }


    @Override
    public ResponseEntity<Result> getLotsFilter(String machCode, Principal principal) {

            return  ResponseEntity.ok(workshopScenePackingService.getLotsByMachCode(machCode,principal));


    }

    @Override
    public ResponseEntity<ObjectResult> cancelLots(Long lotsId, Principal principal) {
        return ResponseEntity.ok(workshopScenePackingService.cancelLots(lotsId, principal));
    }

    @Override
    public ResponseEntity<ObjectResult> getLastOrder(String machCode, Principal principal) {
        return ResponseEntity.ok(workshopScenePackingService.getLastOrder(machCode, principal));
    }

    @Override
    public ResponseEntity<ObjectResult> addLots(OrderCompleteParams orderCompleteParams, Principal principal) {
        return ResponseEntity.ok(workshopScenePackingService.addLots(orderCompleteParams, principal));
    }


}
